{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0a2b83fb",
   "metadata": {},
   "source": [
    "-----\n",
    "* 本学习记录人：马子娟    \n",
    "* 学习时间：2021-11-18 week07   \n",
    "* [参考的文档](https://www.python.org/doc/)   \n",
    "* [许老师博客](https://www.cnblogs.com/xuzhichao)\n",
    "-----"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9756bfcb",
   "metadata": {},
   "source": [
    "# 回顾上周内容：\n",
    "\n",
    "## 1. 认识列表：[value1,value2,value3...]\n",
    "\n",
    "## 2.列表的查询：\n",
    "\n",
    "> 1. 索引值进行查询（单个值）：index\n",
    "> 2. 切片进行查询（多值）：slice\n",
    "\n",
    "## 3.列表的一般方法\n",
    "\n",
    "> 1. 增加元素\n",
    ">> 1.append() 增加元素到列表末尾： L.append(object)\n",
    ">> 2.insert() 指定位置增加元素： L.insert(index)\n",
    "> 2.删除元素\n",
    ">>1.remove() 按照 值 进行删除： L.remove(value)\n",
    ">>2. pop()按照 索引值 进行删除： L.pop(index)注意：不写index默认删除列表的最后一个元素\n",
    "> 3. 修改内容\n",
    "> 4. 查询内容（参考上述2）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c604394b",
   "metadata": {},
   "source": [
    "# 2 本周内容：\n",
    "\n",
    "## 2.1 列表的其他方法\n",
    "\n",
    "## 2.2 列表的实践（课本）\n",
    "\n",
    "## 2.3 列表的实践（课外）\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c78ff07a",
   "metadata": {},
   "source": [
    "# 3 列表的其他方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "6d5bef77",
   "metadata": {},
   "outputs": [],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jan\",\"Jack\"] "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "e7c9add8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Mary', 'Jan', 'Jack']"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "affc293d",
   "metadata": {},
   "source": [
    "> 1. clear()\n",
    ">> 使用方法： L.clear()   \n",
    ">> 结果：remove all items from L"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "5c385155",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function clear:\n",
      "\n",
      "clear() method of builtins.list instance\n",
      "    Remove all items from list.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.clear)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "5b9c91d5",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.clear()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "f3bc047b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "620098c8",
   "metadata": {},
   "source": [
    "> 2. count()\n",
    ">>1.使用方法： L.count(value)   \n",
    ">>2.结果：查询某个value出现的次数（共出现的次数），通常用在计算词频、统计操作当中"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "68aeadf2",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name '分数_list' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-8-bd931e5918b2>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mhelp\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0m分数_list\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcount\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m: name '分数_list' is not defined"
     ]
    }
   ],
   "source": [
    "help(分数_list.count)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "f0a04e1b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[88, 89, 78, 88, 90, 93, 88]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "分数_list =[88,89,78,88,90,93,88]\n",
    "分数_list"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "baec9024",
   "metadata": {},
   "source": [
    "> 3. extend() 扩展\n",
    ">>1.使用方法：L.extend(iterable)\n",
    ">>2.结果：iterable 将拼接在 L 的后面（末尾）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "9ab05d10",
   "metadata": {},
   "outputs": [],
   "source": [
    "分数_list数媒技术1班 =[88,89,68,78,88,90,93,88]\n",
    "分数_list数媒技术2班 =[88,78,77,88,89,77,66]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "304666a8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function extend:\n",
      "\n",
      "extend(iterable, /) method of builtins.list instance\n",
      "    Extend list by appending elements from the iterable.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(分数_list.extend)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "44f4e86c",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name '分数_list_数媒技术1班' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-12-13ca2fbce0ca>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0m分数_list_数媒技术1班\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mextend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0m分数_list_数媒技术2班\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m: name '分数_list_数媒技术1班' is not defined"
     ]
    }
   ],
   "source": [
    "分数_list_数媒技术1班.extend(分数_list_数媒技术2班)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "c519821b",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name '分数_list_数媒技术1班' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-13-1f85b692e40b>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0m分数_list_数媒技术1班\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m: name '分数_list_数媒技术1班' is not defined"
     ]
    }
   ],
   "source": [
    "分数_list_数媒技术1班"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "9cf50e3a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[88, 89, 68, 78, 88, 90, 93, 88, 88, 78, 76, 77, 88, 89, 77, 66]"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 等价于\n",
    "[88,89,68,78,88,90,93,88] + [88,78,76,77,88,89,77,66]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "59f170ab",
   "metadata": {},
   "source": [
    ">  4.<font style =\"color:red\">** copy()\n",
    ">> 在列表中，\"赋值\" 不等价于 \"复制\"   \n",
    ">> 真正的复制列表的两种常见方法   \n",
    ">>> copy()   \n",
    ">>> 切片[:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "8a9ad695",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Jack Alex\n",
      "1708906308976 1708906354608\n",
      "name1 和 name2 拥有不同的数据地址\n"
     ]
    }
   ],
   "source": [
    "name1 = \"Alex\"\n",
    "\n",
    "name2 = name1\n",
    "\n",
    "name1 = \"Jack\"\n",
    "\n",
    "print(name1,name2)\n",
    "print(id(name1),id(name2))\n",
    "print(\"name1 和 name2 拥有不同的数据地址\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f46ef455",
   "metadata": {},
   "source": [
    "* 结论是：赋值有两种情况：\n",
    "> 1. 赋值的数据类型是 不可变的数据 （字符串、数值、元组），分配不同的数据地址\n",
    "> 2. 赋值的数据类型是 可变的数据（列表）分配同一个地址，指向同一个列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "b70bac8f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 此案例 来源： 课本p72：看起来像复制，但其实不是\n",
    "first = [1,2,3,4,5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "1b010a2f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, 5]"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "first"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "0a72e818",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1708906353088\n"
     ]
    }
   ],
   "source": [
    "print(id(first))# first 的 数据地址： 140454682100488"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "87cfac65",
   "metadata": {},
   "outputs": [],
   "source": [
    "second = first"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "e97e9185",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, 5]"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "second"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "055d3161",
   "metadata": {},
   "outputs": [],
   "source": [
    "first.append(6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "8894467b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 5, 6] [1, 2, 3, 4, 5, 6]\n"
     ]
    }
   ],
   "source": [
    "print(first,second)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "57f7d2c5",
   "metadata": {},
   "source": [
    "### 列表的复制（方法一）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "0d7b1a76",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 5, 6] [1, 2, 3, 4, 5, 6]\n",
      "1708905443392 1708905417600\n"
     ]
    }
   ],
   "source": [
    "first = [1,2,3,4,5,6]\n",
    "second = first.copy()\n",
    "\n",
    "print(first,second)\n",
    "print(id(first),id(second))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "efa18afe",
   "metadata": {},
   "outputs": [],
   "source": [
    "first.append(6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "e35eac07",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 5, 6, 6] [1, 2, 3, 4, 5, 6]\n"
     ]
    }
   ],
   "source": [
    "print(first,second)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "af35089d",
   "metadata": {},
   "source": [
    "### 列表的复制（方法二）\n",
    "* 切片[:]可以实现真正意义的复制"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "4cc3ee14",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 2, 4, 5, 6] [1, 2, 2, 4, 5, 6]\n",
      "1708905417216 1708905417088\n"
     ]
    }
   ],
   "source": [
    "first = [1,2,2,4,5,6]\n",
    "second =first[:]\n",
    "\n",
    "print(first,second)\n",
    "print(id(first),id(second))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b281da20",
   "metadata": {},
   "source": [
    "# 思考 copy()只复制 第一层"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "bea09113",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, [4, 5, 6]] [1, 2, 3, [4, 5, 6]]\n",
      "1708904611904 1708904597248\n"
     ]
    }
   ],
   "source": [
    "first = [1,2,3,[4,5,6]]\n",
    "second = first.copy()\n",
    "\n",
    "print(first,second)\n",
    "print(id(first),id(second))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "9a99f078",
   "metadata": {},
   "outputs": [],
   "source": [
    "first[3].append(7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "000343ac",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, [4, 5, 6, 7]]"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "first"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "884545ec",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, [4, 5, 6, 7]]"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "second"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e4380040",
   "metadata": {},
   "source": [
    "> 6.sort()\n",
    ">>1. reverse=False (默认从小到大)\n",
    ">>2. 可修改 rsverse=True(从大到小)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "97320097",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name '分数_list_数媒技术1班' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-71-a924589bd6b7>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mhelp\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0m分数_list_数媒技术1班\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msort\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m: name '分数_list_数媒技术1班' is not defined"
     ]
    }
   ],
   "source": [
    "help(分数_list_数媒技术1班.sort)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "4dcbc1c7",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name '分数_list_数媒技术1班' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-72-9dae611059f0>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0m分数_list_数媒技术1班\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msort\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m: name '分数_list_数媒技术1班' is not defined"
     ]
    }
   ],
   "source": [
    "分数_list_数媒技术1班.sort()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "id": "591c175a",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name '分数_list_数媒技术1班' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-73-1f85b692e40b>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0m分数_list_数媒技术1班\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m: name '分数_list_数媒技术1班' is not defined"
     ]
    }
   ],
   "source": [
    "分数_list_数媒技术1班"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "406efb37",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name '分数_list_数媒技术1班' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-74-be53e1bc98b4>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0m分数_list_数媒技术1班\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msort\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mserverse\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m: name '分数_list_数媒技术1班' is not defined"
     ]
    }
   ],
   "source": [
    "分数_list_数媒技术1班.sort(serverse = True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "6de00873",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name '分数_list_数媒技术1班' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-75-1f85b692e40b>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0m分数_list_数媒技术1班\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m: name '分数_list_数媒技术1班' is not defined"
     ]
    }
   ],
   "source": [
    "分数_list_数媒技术1班"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "133e3776",
   "metadata": {},
   "source": [
    "# 列表的实践（课本）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "041d1765",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'time' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-16-69d25c322ad1>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;31m# 目标： \"Don't panic\" => \"on tap\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[1;31m# 利用列表的 方法 实现\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0m实践一运行前时间\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtime\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtime\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      4\u001b[0m \u001b[0mphrase\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m\"Don't panic!\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      5\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mNameError\u001b[0m: name 'time' is not defined"
     ]
    }
   ],
   "source": [
    "# 目标： \"Don't panic\" => \"on tap\"\n",
    "# 利用列表的 方法 实现\n",
    "实践一运行前时间 = time.time()\n",
    "phrase = \"Don't panic!\"\n",
    "\n",
    "plist = list(phrase) # list(): str --> list\n",
    "print(plist)\n",
    "# 删除 D\n",
    "plist.remove('D')\n",
    "# print(plist)\n",
    "# 删除末尾4个元素 用pop()删除4次\n",
    "for i in range(4):\n",
    "    plist.pop()\n",
    "# print(plist)\n",
    "# 删除‘'’\n",
    "plist.pop(2)\n",
    "# print(plist)\n",
    "# plist.extend([plist.pop(),plist.pop()]) # 难点在于 ：执行的运算先后顺序 先算圆括号，圆括号中从左往右运算\n",
    "# ['o','n','t',' ']  + [ 'a'   ，   'p'  ]\n",
    "plist.insert(4,plist.pop())\n",
    "# print(plist)\n",
    "plist.insert(2,plist.pop(3))\n",
    "#['o', 'n', 't','a','p']  在第二个位置增加  ' '\n",
    "# print(plist)\n",
    "new_phrase = ''.join(plist)\n",
    "print(plist)\n",
    "print(new_phrase)\n",
    "实践一运行后时间 = time.time()\n",
    "实践一代码的执行实践 = 实践一运行后时间-实践一运行前时间\n",
    "print(实践一代码的执行实践)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "beb58b91",
   "metadata": {},
   "source": [
    "# 列表的实践二（课本）\n",
    "\n",
    "* 对比 列表的实践一 结论：\n",
    "> 1. 列表的方法 会修改 原本的列表 但是 **列表的切片** 不改变原列表\n",
    "> 2. 使用列表的方法时，需考虑是否需要先复刻列表\n",
    "> 3. 思考如何对比代码的执行效率？代码执行后的时间-代码执行前的时间"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "id": "af8931af",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1637241127.8831482"
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import time\n",
    "time.time()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "id": "810b401a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<function list.extend(iterable, /)>"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 目标：\"Don't panic\" => \"on tap\"\n",
    "# 利用列表的 切片 实现\n",
    "实践二运行前时间 = time.time()\n",
    "phrase = \"Don't panic!\"\n",
    "\n",
    "plist = list(phrase) # list(): str --> list\n",
    "print(plist)\n",
    "\n",
    "plist[1:3].extend"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "id": "f29ab962",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "'list' object is not callable",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-93-5235c9c5d07e>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mplist\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m5\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mplist\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m4\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m+\u001b[0m\u001b[0mplist\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m7\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m+\u001b[0m\u001b[0mplist\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m6\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m: 'list' object is not callable"
     ]
    }
   ],
   "source": [
    "plist[5]=plist([4])+plist([7])+plist([6])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "id": "7be1d9fe",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'t'"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plist[4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "id": "3abde496",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[' ']"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(plist[5])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b59fd0c9",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
